package com.easy.service.impl;

import com.easy.bean.Department;
import com.easy.mapper.DepartmentDao;
import com.easy.service.DepartmentService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import org.springframework.stereotype.Service;

@Service
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    DepartmentDao departmentDao;
    @Override
    public Department add(Department department){
        //新增数据
        departmentDao.add(department);
        Department result=departmentDao.one(department.getId());
        return result;
    }

    @Override
    public int del(Integer id) {
        return departmentDao.del(id);
    }

    @Override
    public Department edit(Department department) {
        departmentDao.edit(department);
        Department result=departmentDao.one(department.getId());
        return result;
    }

    @Override
    public List<Department> all(String name, String description) {
        return departmentDao.all(name, description);
    }


    @Override
    public Department one(Integer id) {
        return departmentDao.one(id);
    }

    public void page(Page page, Department department){
        int count=departmentDao.pageCount(department);
        Object data=departmentDao.page(page, department);
        page.setCount(count);
        page.setData(data);
    }
}
